package com.his.modules.business.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.his.modules.business.dto.MsCf02KcDto;
import com.his.modules.business.entity.MsCf02;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface MsCf02Mapper extends BaseMapper<MsCf02> {

    @Select({"  SELECT YK_TYPK.YPXH,    " +
            "         YK_TYPK.YPMC,     " +
            "         V_MS_CF02.YFGG,   " +
            "         V_MS_CF02.YFDW,   " +
            "         V_MS_CF02.YPSL,   " +
            "         V_MS_CF02.FYGB,   " +
            "         V_MS_CF02.CFTS,   " +
            "         V_MS_CF02.ZFBL,   " +
            "         V_MS_CF02.YPDJ,   " +
            "         V_MS_CF02.CFSB,   " +
            "         V_MS_CF02.YPXH,   " +
            "         V_MS_CF02.YPCD,   " +
            "         V_MS_CF02.YPYF,   " +
            "         V_MS_CF02.YFBZ,   " +
            "         V_MS_CF02.XMLX,   " +
            "         V_MS_CF02.SBXH,   " +
            "( SELECT sum(YF_KCMX.YPSL) " +
            "  FROM YF_KCMX" +
            "  WHERE YF_KCMX.YFSB = #{yfsb} " +
            "  AND YF_KCMX.CKBH = #{ckbh} " +
            "  AND YF_KCMX.YPXH = V_MS_CF02.YPXH " +
            "  AND YF_KCMX.YPCD = V_MS_CF02.YPCD " +
            "  AND YF_KCMX.JYBZ = 0     " +
            "  AND YF_KCMX.JGID = #{jgid} ) AS YFKC, " +
            "         0    AS JYBZ,     " +
            "         V_MS_CF02.SBXH,   " +
            "         V_MS_CF02.YCJL,   " +
            "         V_MS_CF02.GYTJ,   " +
            "         V_MS_CF02.YYTS,   " +
            "         V_MS_CF02.HJJE,   " +
            "         V_MS_CF02.PSJG,   " +
            "         V_MS_CF02.PSPB    " +
            "    FROM V_MS_CF02,        " +
            "         YK_CDDZ,          " +
            "         YK_TYPK           " +
            "    WHERE ( V_MS_CF02.CFSB = #{cfsb} ) " +
            "    and  ( V_MS_CF02.YPCD = YK_CDDZ.YPCD ) " +
            "    and  ( V_MS_CF02.YPXH = YK_TYPK.YPXH ) " +
            "    and  ( V_MS_CF02.JGID = #{jgid} )"})
    List<MsCf02KcDto> getMsCf02KcDto(Long cfsb, Long yfsb, Long jgid, Integer ckbh);
}